package com.racetrack

class Race {

    String name
    Date startDate
    String city
    String state
    BigDecimal distance
    BigDecimal cost
    Integer maxRunner = 100000

	static searchable = true
    static mapping = {

        // specify returning order by
        sort("startDate")
    }

    // use comma , to add more
    static hasMany = [regs:Registration]
    
    static constraints = {

        name(blank: false, maxSize: 50)
        startDate(validator:{ return (it > new Date())} )
        
        city()
        state(inList: ["Shanxi","Jiangsu","Hubei","Shanghai"], blank: false)
        distance(min: 0.0, scale: 3)
        cost(min: 0.0, max: 100.0)
        maxRunner(min: 0, max: 100000)
    }

    String toString(){
        return "${name}, ${startDate.format('MM/dd/yyyy')}"
    }
}
